package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CarUseView;
import com.ruoyi.system.service.ICarUseViewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汽车使用情况Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/system/carUseView")
public class CarUseViewController extends BaseController
{
    @Autowired
    private ICarUseViewService carUseViewService;

    /**
     * 查询汽车使用情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:carUseView:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarUseView carUseView)
    {
        startPage();
        List<CarUseView> list = carUseViewService.selectCarUseViewList(carUseView);
        return getDataTable(list);
    }

    @Anonymous
    @GetMapping("/charts")
    public List<CarUseView> charts(CarUseView carUseView)
    {
        return carUseViewService.selectCarUseViewList(carUseView);
    }
    /**
     * 导出汽车使用情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:carUseView:export')")
    @Log(title = "汽车使用情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarUseView carUseView)
    {
        List<CarUseView> list = carUseViewService.selectCarUseViewList(carUseView);
        ExcelUtil<CarUseView> util = new ExcelUtil<CarUseView>(CarUseView.class);
        util.exportExcel(response, list, "汽车使用情况数据");
    }

    /**
     * 获取汽车使用情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:carUseView:query')")
    @GetMapping(value = "/{carBrand}")
    public AjaxResult getInfo(@PathVariable("carBrand") String carBrand)
    {
        return success(carUseViewService.selectCarUseViewByCarBrand(carBrand));
    }

    /**
     * 新增汽车使用情况
     */
    @PreAuthorize("@ss.hasPermi('system:carUseView:add')")
    @Log(title = "汽车使用情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarUseView carUseView)
    {
        return toAjax(carUseViewService.insertCarUseView(carUseView));
    }

    /**
     * 修改汽车使用情况
     */
    @PreAuthorize("@ss.hasPermi('system:carUseView:edit')")
    @Log(title = "汽车使用情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarUseView carUseView)
    {
        return toAjax(carUseViewService.updateCarUseView(carUseView));
    }

    /**
     * 删除汽车使用情况
     */
    @PreAuthorize("@ss.hasPermi('system:carUseView:remove')")
    @Log(title = "汽车使用情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carBrands}")
    public AjaxResult remove(@PathVariable String[] carBrands)
    {
        return toAjax(carUseViewService.deleteCarUseViewByCarBrands(carBrands));
    }
}
